<!DOCTYPE html>
<html style="height:100%;">
<head>
    <meta http-equiv="content-type" content="text/html;charset=UTF-8"/>
    <title>Java体系树</title>

</head>
<body style="height:100%;margin: 0;">
    <div id="container" style="height: 100%;"></div>

    <!-- JS Scripts -->
    <!-- ECharts -->
    <script src="../static/js/echarts.js"></script>
    <script>
        var dom = document.getElementById("container");
        var myChart = echarts.init(dom);
        var app = {};
        option = null;
        /*
           判断结点是否是叶结点
         */
        function isLeaf(node) {
            return node.data.children == null;
        };
        myChart.on('click',function (node) {//data为Event type
            if(isLeaf(node)){//叶节点
                window.location.href = 'articles.html?keywords=' + node.name;
            }
        });
        myChart.showLoading();
        var data = {
            "name": "Java技能树",
            "children": [
                {
                    "name": "计算机基础",
                    "children": [
                        {
                            "name": "操作系统"
                        },
                        {
                            "name": "编译原理"
                        },
                        {
                            "name": "计算机网络"
                        },
                        {
                            "name": "互联网协议",
                            "children": [
                                {"name": "TCP/IP"},
                                {"name": "HTTP"},
                                {"name": "HTTPS"},
                                {"name": "OAuth"},
                                {"name": "REST"}
                            ]
                        },
                    ]
                },
                {
                    "name": "Java基础"
                },
                {
                    "name": "Java框架",
                    "children": [
                        {"name": "Spring"}
                    ]
                },
            ]
        };

        myChart.hideLoading();

        echarts.util.each(data.children, function (datum, index) {
            index % 2 === 1 && (datum.collapsed = true);
        });

        myChart.setOption(option = {
            tooltip: {
                trigger: 'item',
                triggerOn: 'mousemove'
            },
            legend: {
                top: '2%',
                left: '3%',
                orient: 'vertical',
                data: [
                    {
                        name: 'Java技能树',
                        icon: 'rectangle',
                    }
                ],
            },
            series:[
                {
                    type: 'tree',
                    name: 'Java技能树',
                    data: [data],
                    /*
                    itemStyle: {
                        normal: {
                            color: "#000000",
                            lineStyle: {
                                color: "#000000"
                            },
                            borderColor: '#ffc600',
                        }
                    },
                    */
                    symbol: 'emptyCircle',
                    symbolSize: 7,

                    top: '1%',
                    left: '7%',
                    bottom: '1%',
                    right: '20%',

                    label: {
                        normal: {
                            position: 'left',
                            verticalAlign: 'middle',
                            align: 'right'
                        }
                    },

                    leaves: {
                        label: {
                            normal: {
                                position: 'right',
                                verticalAlign: 'middle',
                                align: 'left'
                            }
                        }
                    },

                    expandAndCollapse: true,

                    animationDuration: 550,
                    animationDurationUpdate: 750

                }
            ]
        });

        ;
        if (option && typeof option === "object") {
            myChart.setOption(option, true);
        }
    </script>
</body>
</html>